#!/usr/bin/php
<?PHP

$fp =  fopen("test_file", "r+");

if (flock($fp, LOCK_EX))
{
    echo "flcok ==> $argc\n";
    if ($argc > 1) {
        fwrite($fp, "write ".$argv[1]."\n");
    } else {
        fwrite($fp, "write success!\n");
        sleep(5);
        flock($fp, LOCK_UN);
        sleep(5);
    }
}

ftruncate($fp, 1024 * 1024);

fclose($fp);



